package com.softserveinc.edu.oms.persistence.dao.concrete;

import org.hibernate.Query;
import org.hibernate.SessionFactory;

import com.softserveinc.edu.oms.persistence.dao.HibernateDao;
import com.softserveinc.edu.oms.persistence.entities.CustomerType;
/**
 * 
 * @author roman
 * @version 1.0
 */
public class CustomerTypeDao extends HibernateDao<CustomerType> {

	/**
	 * 
	 * @param sessionFactory
	 */
	public CustomerTypeDao(final SessionFactory sessionFactory) {
		super(CustomerType.class, sessionFactory);
	}
	
	/**
	 * 
	 * @return CustomerType Object with details about Standard type
	 * Discount
	 */
	public CustomerType getStandartTypeDiscount() {
		CustomerType customerType;

		openSessionAndBeginTransaction();

		// creating a query
		Query query = session.createQuery("from CustomerType customerT "
				+ "where customerT.typeName = :Standard").setString("Standard", "Standard");
		customerType = (CustomerType) query.uniqueResult();

		commitTransactionAndCloseSession();
		
		return customerType;
	}

	/**
	 * 
	 * @return CustomerType Object with details about Silver type
	 * Discount
	 */
	public CustomerType getSilverTypeDiscount() {
		CustomerType customerType;

		openSessionAndBeginTransaction();

		// creating a query
		Query query = session.createQuery("from CustomerType customerT "
				+ "where customerT.typeName = :Silver").setString("Silver", "Silver");
		customerType = (CustomerType) query.uniqueResult();
		
		commitTransactionAndCloseSession();

		return customerType;
	}

	/**
	 * 
	 * @return CustomerType Object with details about Gold type
	 * Discount
	 */
	public CustomerType getGoldTypeDiscount() {
		CustomerType customerType;

		openSessionAndBeginTransaction();

		// creating a query
		Query query = session.createQuery("from CustomerType customerT "
				+ "where customerT.typeName = :Gold").setString("Gold", "Gold");
		customerType = (CustomerType) query.uniqueResult();
		
		commitTransactionAndCloseSession();

		return customerType;
	}

	/**
	 * 
	 * @return CustomerType Object with details about Platinum type
	 * Discount
	 */
	public CustomerType getPlatinumTypeDiscount() {
		CustomerType customerType;

		openSessionAndBeginTransaction();

		// creating a query
		Query query = session.createQuery("from CustomerType customerT "
				+ "where customerT.typeName = :Platinum").setString("Platinum", "Platinum");
		customerType = (CustomerType) query.uniqueResult();
		
		commitTransactionAndCloseSession();

		return customerType;
	}
}
